//
//  CustomAlertController.m
//  Eath
//
//  Created by mao on 11/5/14.
//  Copyright (c) 2014 yuhaya. All rights reserved.
//

#import "CustomAlertController.h"
#import "Tool.h"

@interface CustomAlertController ()

@end

@implementation CustomAlertController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    UILabel * title = [[UILabel alloc] init];
    title.frame = CGRectMake(0, 0, 300, 40);
    title.textAlignment = NSTextAlignmentCenter;
    title.text = @"选择时间";
    
    [self.view addSubview:title];
    
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [leftBtn setTitle:@"取消" forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
    leftBtn.frame = CGRectMake(0, 0, 60, 40);
    [self.view addSubview:leftBtn];
    
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [rightBtn setTitle:@"确定" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    rightBtn.frame = CGRectMake(240, 0, 60, 40);
    [self.view addSubview:rightBtn];
    
    for (int a = 0; a <= 3; a++) {
        UIAlertAction * aa = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
        [self addAction:aa];
    }
    
    UIDatePicker * date = [[UIDatePicker alloc] init];
    self.time = date;
    date.frame = CGRectMake(1, 40, 303, 150);
    date.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
    date.datePickerMode = UIDatePickerModeTime;
    [self.view addSubview:date];
}

-(void)cancel
{
    [self dismissViewControllerAnimated:YES completion:^(){
        
    }];
}

-(BOOL)submit
{
    NSDate * date = self.time.date;
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HH:mm"]; // 这里是用大写的 H
    NSString * dateStr = [dateFormatter stringFromDate:date];
    self.label.text = dateStr;
    
    BOOL flag = [Tool setUserSetting:self.stu.identify andItem:self.config_item andVal:dateStr];
    [self cancel];
    return flag;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
